// -----------------------------------------------
// Author:     code34 nicolas_boiteux@yahoo.fr
// Edited by:  Neumatic
// Warcontext: - Compute groups/vehicles in the locations around the mission
// -----------------------------------------------
if (!isServer) exitWith {};

private [
	"_locations",
	"_temp",
	"_marker",
	"_count",
	"_location",
	"_position"
];

_location = _this select 0;

_count = 0;
_position = position _location;

if (wckindofserver == 3) then {
	wcambiantdistance = 2500;
};

// Create enemies around target
_locations = nearestLocations [_position, ["NameCityCapital", "NameCity", "NameVillage", "Name", "Hill", "Mount"], wcambiantdistance];
{
	if (_position distance position _x < 500) then {
		_locations = _locations - [_x];
	};
} foreach _locations;

wcambiantdistance = wcambiantdistance + 200;

sleep 1;

while {count _locations > wclevelmaxoutofcity} do {
	_temp = _locations call BIS_fnc_selectRandom;
	_locations = _locations - [_temp];
};

{
	if (wcwithcomposition == 1) then {
		wcgarbage = [_x] spawn WC_fnc_createcomposition;
	};

	_marker = [format ["ambiant%1", wcambiantindex], (wcdistance * 2), position _x, "ColorRed", "ELLIPSE", "FDIAGONAL", "EMPTY", 0, "", false] call WC_fnc_createmarkerlocal;
	wcambiantmarker = wcambiantmarker + [_marker];
	wcambiantindex = wcambiantindex + 1;
	_count = _count + 1;

	if (random 1 > 0.7) then {
		wcgarbage = [_marker, (wcvehicleslistE call BIS_fnc_selectRandom), true] spawn WC_fnc_creategroup;
	} else {
		wcgarbage = [_marker, (wcfactions call BIS_fnc_selectRandom), false] spawn WC_fnc_creategroup;
	};
	sleep 1;
} foreach _locations;

diag_log format ["WARCONTEXT: COMPUTE %1 AMBIANT GROUPS", _count];